package com.woniuxy.controller;


import com.woniuxy.dto.MyDto;
import com.woniuxy.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class AliPayController {
    @Autowired
    private AlipayService alipayService;


    @RequestMapping("/pay")
    public void payMent(HttpServletResponse response, HttpServletRequest request,String order_number,String total_amount,String subject ) {
        try {
            alipayService.aliPay(response,request,order_number,total_amount,subject);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param out_biz_no  订单ID
     * @param payee_account 用户ID pxhclk2846@sandbox.com
     * @param payee_real_name  真实姓名   沙箱环境
     * @param amount 金额
     */
    @RequestMapping("/zhuan")
    public MyDto zhuan(String out_biz_no, String payee_account, String payee_real_name, String amount){
        System.out.println(amount);
       MyDto myDto=new MyDto();
        try {
            alipayService.zhuan(out_biz_no,payee_account,payee_real_name,amount);
            myDto.setCode(200);
            myDto.setMsg("转账成功");
        }catch (Exception e){
            e.printStackTrace();
            myDto.setCode(-200);
            myDto.setMsg("转账失败");
        }
        return  myDto;
    }
    @GetMapping("/test")
    public String test(){
        return "nacos测试";
    }
}
